package com.sunwayworld.common.utils;

import java.io.Serializable;


/**
 * 
 * <p>
 * Title: SplitPage 分页类
 * </p>
 * 
 * <p>
 * Description: 分页类 包含当前页，每页显示行数
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2005
 * </p>
 * 
 * <p>
 * Company:
 * </p>
 * 
 * @author sagitta
 * @version 1.0
 */
public class SplitPage implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int CONST_CURRPAGE=1;
	public static final int CONST_NUMPERPAGE=10;
	public static final int CONST_MAX_NUMPERPAGE=99999;
	
	private int currPage = CONST_CURRPAGE; // 当前页面

	private int numPerPage = CONST_NUMPERPAGE; // 每页显示行数

	public SplitPage() {
	}

	public SplitPage(int currPage, int numPerPage) {
		this.currPage = currPage;
		this.numPerPage = numPerPage;
	}

	public SplitPage(Integer currPage, Integer numPerPage) {
		try {
			this.currPage = currPage.intValue();
		} catch (Exception ex) {
			this.currPage = CONST_CURRPAGE;
		}
		try {
			this.numPerPage = numPerPage.intValue();
		} catch (Exception ex) {
			this.numPerPage = CONST_NUMPERPAGE;
		}

	}

	public SplitPage(String currPage, String numPerPage) {
		try {
			this.currPage = Integer.parseInt(currPage);
		} catch (Exception ex) {
			this.currPage = CONST_CURRPAGE;
		}
		try {
			this.numPerPage = Integer.parseInt(numPerPage);
		} catch (Exception ex) {
			this.numPerPage = CONST_NUMPERPAGE;
		}
	}

	public int getCurrPage() {
		if (currPage < 1) {
			currPage = CONST_CURRPAGE;
		}
		return currPage;
	}

	public int getNumPerPage() {
		if (numPerPage < 0) {
			numPerPage = CONST_NUMPERPAGE;
		}
		if (numPerPage ==0) {
			numPerPage = 1;
		}
		return numPerPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public void setNumPerPage(int numPerPage) {
		this.numPerPage = numPerPage;
	}
	public int getCurrRow(){
		return currPage*numPerPage+1;
	}
	
}
